import RNFS from 'react-native-fs';
/*
应用的文件目录
/data/user/0/com.rnbcos/files/
/data/data/com.rnbcos/files
 */

export default class FileUtils {
  static basePath = RNFS.DocumentDirectoryPath + '/';
  static readFileContent = async filePath => {
    try {
      const content = await RNFS.readFile(
        FileUtils.basePath + filePath,
        'utf8',
      );
      console.log('File content:', content);
      return content;
    } catch (error) {
      console.log('Error reading file:', error);
      return undefined;
    }
  };

  static write_file = async (filePath, content) => {
    try {
      console.log('basePath is :' + FileUtils.basePath);
      await RNFS.writeFile(FileUtils.basePath + filePath, content, 'utf8');
      console.log('File written successfully.');
      return 0;
    } catch (error) {
      console.log('Error writing file:', error);
      return error;
    }
  };
}
